<!-- 客户模块 -->
<template>
  <a-form class="smart-query-form">
    <a-row class="smart-query-form-row">
      <a-form-item label="客户名称" class="smart-query-form-item" name="name">
        <a-input v-model:value="searchParam.name" placeholder="请输入客户名称" />
      </a-form-item>
      <a-form-item label="业务人员" class="smart-query-form-item" name="businessImplementer">
        <DictSelect :service-id="SERVICE_ID_ENUM.USER.value" v-model:value="searchParam.businessImplementer" />
      </a-form-item>
      <a-form-item class="smart-query-form-item smart-margin-left10">
        <a-button type="primary" @click="search">
          <template #icon>
            <SearchOutlined />
          </template>
          查询
        </a-button>
        <a-button @click="reset" style="margin-left: 6px;">
          <template #icon>
            <ReloadOutlined />
          </template>
          重置
        </a-button>
      </a-form-item>
    </a-row>
  </a-form>
  <a-card size="small" :bordered="false" :hoverable="true">
    <a-row class="smart-table-btn-block">
      <div class="smart-table-operate-block">
        <a-button @click="showForm()" type="primary" size="small">
          <template #icon>
            <PlusOutlined />
          </template>
          新建
        </a-button>
        <a-button @click="confirmBatchDelete" danger size="small" :disabled="selectedRowKeys.length == 0">
          <template #icon>
            <DeleteOutlined />
          </template>
          批量删除
        </a-button>
      </div>
      <div class="smart-table-setting-block">
        <TableOperator v-model="columns" :tableId="null" :refresh="reset" />
      </div>
    </a-row>
    <a-table :scroll="{ x: 1000 }" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      size="small" :dataSource="tableData" :columns="columns" rowKey="id" :pagination="false" :loading="tableLoading"
      bordered>
      <template #bodyCell="{ column, record, text }">
        <template v-if="column.dataIndex === 'action'">
          <div class="smart-table-operate">
            <a-button @click="showForm(record)" type="link">编辑</a-button>
            <a-button @click="confirmDelete(record)" danger type="link">刪除 </a-button>
          </div>
        </template>
      </template>
    </a-table>
    <div class="smart-query-table-page">
      <a-pagination showSizeChanger showQuickJumper show-less-items :pageSizeOptions="PAGE_SIZE_OPTIONS"
        :defaultPageSize="pageable.pageSize" v-model:current="pageable.pageNum" v-model:pageSize="pageable.pageSize"
        :total="pageable.total" @change="handleSizeChange" :show-total="(total) => `共total条`" />
    </div>
    <formModal ref="baseFormRef" @refresh="ajaxQuery" />
    <UpdateFormModal ref="updateFormModal" @refresh="ajaxQuery" />
  </a-card>
</template>
<script setup>
import { reactive, ref, onMounted, computed } from 'vue';
import { message, Modal } from 'ant-design-vue';
import dayjs from 'dayjs';
import { useTable } from '/@/hooks/useTable';
import { useHandleData } from '/@/hooks/useHandleData';
import DictSelect from '/@/components/cache/dict-select.vue'
import { SERVICE_ID_ENUM, DICT_TYPE_ENUM } from '/@/constants/system/cache-service-id-const';
import { taskApi } from '/@/api/task/task-api';
import { useRouter } from 'vue-router';
import TableOperator from '/@/components/support/table-operator/index.vue';
import { TABLE_ID_CONST } from '/@/constants/support/table-id-const';
import formModal from './components/client-form-modal.vue';
const {
  tableData,
  pageable,
  searchParam,
  searchInitParam,
  isShowPage,
  getTableList,
  search,
  reset,
  tableLoading,
  handleSizeChange,
} = useTable(taskApi.getTestPage);
// --------------------------- 表格 ---------------------------
const columns = ref([
  {
    title: '客户名称',
    dataIndex: 'contact',
    // minWidth: 180,
  },

  {
    title: '客户类型',
    dataIndex: 'implementerName',
    // width: 100,
  },
  {
    title: '客户经理',
    dataIndex: 'taskRate',
    // width: 100,
  },
  {
    title: '服务顾问',
    // width: 100,
    dataIndex: 'planBegin',
  },
  {
    title: '服务状态',
    // width: 100,
    dataIndex: 'planEnd',
  },
  {
    title: '客户等级',
    // width: 100,
    dataIndex: 'approveName',
  },
  {
    title: '所属片区',
    // width: 100,
    dataIndex: 'approveName',
  },
  {
    title: '增值税',
    // width: 120,
    dataIndex: 'stateName',
  },
  {
    title: '成立日期',
    // width: 120,
    dataIndex: 'stateName',
  },
  {
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
    width: 100,
  },
]);

//多选
let selectedRowKeys = ref([]);
let selectedRows = ref([]);
// 是否有选中：用于 批量操作按钮的禁用
const hasSelected = computed(() => selectedRowKeys.value.length > 0);

function onSelectChange(keyArray, selectRows) {
  selectedRowKeys.value = keyArray;
  selectedRows.value = selectRows;

}
const baseFormRef = ref();
function showForm(data) {
  baseFormRef.value.showModal(data);
}


// --------------------------- 删除 ---------------------------

async function confirmDelete(row) {
  let params = { id: row.id };
  await useHandleData(taskApi.getTestPage, params, '确认删除吗');

}

</script>
<style lang="less" scoped></style>
